package com.kobe.game_20;

import java.util.LinkedList;

/**
 * 
 * The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
 * 
 * Find the sum of all the primes below two million.
 * 
 * 
 * the Result is: 142913828922
 * 
 */
public class Game10 {

    public static void main(String[] args) {
        // double time = System.currentTimeMillis();
        // System.out.println("the Result is: " + getPrimeSum(2000000));
        // time = System.currentTimeMillis() - time;
        // System.out.println("time used :" + time);

        LinkedList<Integer> temp = new LinkedList<Integer>();
        Long sum = 0L;
        double time = System.currentTimeMillis();
        for (int i = 0; i <= 20000; i++) {
            if (i > 2 && i % 2 != 0) {
                temp.add(i);
            } else {
                temp.add(0);
            }
        }

        for (int i = 3; i < temp.size(); i = i + 2) {
            int tempNumber = temp.get(i);
            if (tempNumber != 0) {
                sum = sum + tempNumber;
                for (int j = tempNumber; i * j < temp.size(); j++) {
                    temp.set(i * j, 0);
                }
            }
        }

        System.out.println("the result is : " + sum);

        time = System.currentTimeMillis() - time;
        System.out.println("time used :" + time);

    }

//    private static long getPrimeSum(int theNumber) {
//        // sum��int��Χ���洦����ѡ��long
//
//        long sum = 2L;
//        for (int i = 3; i <= theNumber; i = i + 2) {
//            if (Game_7.isPrime(i)) {
//                // System.out.println("the Prime is: " + i);
//                sum = sum + i;
//            }
//        }
//        return sum;
//    }
//
//    private static long getPrimSum_New(int theNumber) {
//        long sum = 0L;
//
//        return sum;
//    }
}
